/** EventEmitter 相关应用实例 */
let events = require('events');

let events_loop_case_1 = function(){
    let eventEmitter = new events.EventEmitter();
    eventEmitter.on('laugh', function(e){console.log('laugh'); console.log(e)});
    eventEmitter.emit('laugh', 'wanghongbin');
};

let events_loop_case_2 = function(){
    let eventEmitter = new events.EventEmitter();
    let connectHandler = function connected(){
        console.log('connected success.');
        eventEmitter.emit('data_received');
    };
    eventEmitter.on('connection', connectHandler);
    eventEmitter.on('data_received', function(){
        console.log('data received success.');
    });
    eventEmitter.emit('connection');
    console.log('program end.');
};
// events_loop_case_2();

let events_loop_case_3 = function(){
    let event = new events.EventEmitter();
    event.on('some_event', function(){
        console.log('some_event emit...');
    });
    setTimeout(()=>{
        event.emit('some_event');
    }, 1000);
};
events_loop_case_3();